# coding: utf8


def test_user_class():
    class Demo:
        def __init__(self, v=100):
            self.v = v

        def __eq__(self, other):
            print('compare')
            if getattr(other, 'v'):
                return self.v == other.v
            else:
                return False

    a = Demo()
    b = Demo()

    print(
        f" >>> print(a, '\\n', b)\n"
        f"{a},\n {b}\n"
        f"{a == b}\n"
        f"{a is b}\n"
        f"\n"
        )

def test_integer():
    # in function space
    # create diff object integer if larger than 2**64
    x = 2**64
    y = 2**64
    print(id(x), id(y))

    print(
        f" >>> x == y\n"
        f"{x == y}\n"
        f" >>> x is y\n"
        f"{x is y}"
    )

def test_container():
    a = [1, 2, [1, 3]]
    b = [1, 2, [1, 3, 2]]
    c = [1, 2, [1, 3]]

    print(
        f" {a[:2] == b[:2]}\n"
        f" {a == b}\n"
        f" {a == c}"
    )

    a, b = [1], [1]
    a.append(b)
    b.append(a)
    try:
        a == b
    except RecursionError as e:
        print(a, b)
        print('list compare Error: a == b')

    print(
        " >>> a, b = [1], [1]\n"
        " >>> a.append(b)\n"
        " >>> b.append(a)\n"
        " >>> print(a, '\\n', b)\n"
        f"{a} \n{b}\n"
        " >>> a == b\n"
        "Traceback (most recent call last):\n"
        " ......\n"
        "  a == b\n"
        "RecursionError: maximum recursion depth exceeded in comparison\n"
        "\n"
        "# but it is easy to see if they are same object by is\n"
        " >>> a is b\n"
        f"{a is b}\n"
        f" >>> id(a), id(b)\n"
        f"{id(a), id(b)}"
    )
